//
//  HRFollowDyanmicInfoViewController.m
//  Hear
//
//  Created by mac on 2017/5/19.
//  Copyright © 2017年 mac. All rights reserved.
// 帖子详情

#import "HRFollowDyanmicInfoViewController.h"
#import "HRDynamicInfoTableViewModel.h"
#import "HRDunamicLayout.h"
#import "HRDynamicInfoViewModel.h"
#import "HRDynamicCommentModel.h"
#import "HRGetLikesModel.h"
#import "MJRefresh.h"
#import "HRUpdataUserInfoModel.h"
#import "HRShowRecordView.h"
#import "HRRecordAudioViewController.h"
#import "HRUMShareTool.h"
#import "HRFollowDynamicHeadView.h"
#import "HRDynamicViewController.h"
#import "HRMessageToolBar.h"
#import "OSSImageUploader.h"
#import "EMVoiceConverter.h"
#import <DZNEmptyDataSet/UIScrollView+EmptyDataSet.h>
#import "HRCommentInfoViewController.h"
@interface HRFollowDyanmicInfoViewController ()<DZNEmptyDataSetSource,DZNEmptyDataSetDelegate>
@property (nonatomic, strong)UITableView *tableView;
@property (nonatomic, strong)HRDynamicInfoTableViewModel *tableViewModel;
@property (nonatomic, strong)HRFollowDynamicHeadView *headView;
@property (nonatomic, strong)HRDynamicInfoViewModel *viewModel;
@property (nonatomic, strong)HRGetLikesModel *likesModel;
@property (nonatomic, assign)NSInteger pIndex;
@property (nonatomic, strong)HRDynamicModel *lastDynamicModel;
/*!
 @property
 @brief 底部输入控件
 */
@property (strong, nonatomic) HRMessageToolBar *chatToolbar;


/*!
 @property
 @brief 底部表情控件
 */
@property(strong, nonatomic) EaseFaceView *faceView;

/*!
 @property
 @brief 底部录音控件
 */
@property(strong, nonatomic) HRMeeageRecordView *recordView;

@property (weak, nonatomic) id<EaseMessageViewControllerDataSource> dataSource;
@property (weak, nonatomic) id<EaseMessageViewControllerDelegate> delegate;

@property (nonatomic, strong)HRDynamicCommentModel *tempCommentModel; // 回复的人的model

@property(nonatomic, strong)HRDynamicCommentModel *lastCommentModel;

@end

@implementation HRFollowDyanmicInfoViewController
#pragma mark - Get and Set



-(HRFollowDynamicHeadView *)headView{
    if (!_headView){
        WeakSelf
        _headView = [[HRFollowDynamicHeadView alloc] initWithFrame:CGRectMake(0, 0, kFullWidth, self.layout.cellHeight)];
        _headView.layout = self.layout;
        _headView.likeButtonClickBlock = ^(BOOL isLike){
            [weakSelf getDynamicLike:isLike];
        };
        _headView.playMedioBlock = ^(HRDynamicModel *currentDynamicModel){
            HRFollowDynamicLayout *layout = [HRFollowDynamicLayout new];
            layout.style = HRFollowLayoutStyleDetail;
            layout.dynamicModel = currentDynamicModel;
            weakSelf.headView.layout = layout;
        };
        _headView.clickIconBock = ^(){
            if ([weakSelf.layout.dynamicModel.UserLocalId isEqualToString:USERID]) return ;
            HRDynamicViewController *dynamicVC = [HRDynamicViewController new];
            dynamicVC.currentUserID = weakSelf.layout.dynamicModel.UserLocalId;
            [weakSelf.navigationController pushViewController:dynamicVC animated:YES];
        };
    }
    return _headView;
}


-(HRGetLikesModel *)likesModel{
    if (_likesModel == nil){
        _likesModel = [HRGetLikesModel new];
    }
    return _likesModel;
}

-(HRDynamicInfoViewModel *)viewModel{
    if (!_viewModel){
        _viewModel = [HRDynamicInfoViewModel new];
    }
    return _viewModel;
}
-(HRDynamicInfoTableViewModel *)tableViewModel{
    if (!_tableViewModel){
        WeakSelf
        _tableViewModel = [HRDynamicInfoTableViewModel new];
        _tableViewModel.deleteCommentBlock = ^(NSUInteger index){
            [weakSelf deleteCommentIndex:index];
        };
        _tableViewModel.iconTapBock = ^(NSString *currentUserID){
            HRDynamicViewController *VC = [HRDynamicViewController new];
            VC.currentUserID = currentUserID;
            [weakSelf.navigationController pushViewController:VC animated:YES];
        };
        _tableViewModel.clickIndexrowBlock = ^(HRDynamicCommentModel *commentModel){
            [weakSelf towAnswerForSomenone:commentModel]; // 二级评论
        };
        
        _tableViewModel.playCommentMedioBlock = ^(HRDynamicCommentModel *currentCommentModel){
            
        };
        _tableViewModel.scrollViewWillBeginDraggingBlock = ^(){
            [weakSelf.chatToolbar endEditing:YES];

        };
        _tableViewModel.commentClickBlock = ^(HRDynamicCommentModel *commentModel){
            HRCommentInfoViewController *VC = [HRCommentInfoViewController new];
            VC.title = [NSString stringWithFormat:@"%lu条评论",(unsigned long)commentModel.ChildComments.count];
            VC.commentModel = commentModel;
            VC.dynamicLocalId = self.layout.dynamicModel.LocalId;
            [weakSelf.navigationController pushViewController:VC animated:YES];
        };
        
    }
    return _tableViewModel;
}

-(instancetype)init
{
    self = [super init];
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"详情";
    

    
    self.layout.dynamicModel.isPlaying = NO;
    
    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.tableView];
    self.tableView.tableHeaderView = self.headView;
    [self.tableViewModel handleWithTable:self.tableView];
    
    self.tableView.emptyDataSetDelegate = self;
    self.tableView.emptyDataSetSource = self;

//    UIButton *leftButton = [UIButton buttonWithType:0];
//    leftButton.size = CGSizeMake(20, 20);
//    [leftButton setImage:[UIImage imageNamed:@"Back-Arrow"] forState:UIControlStateNormal];
//    [leftButton addTarget:self action:@selector(clickBack) forControlEvents:UIControlEventTouchUpInside];
//    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
//    self.navigationItem.leftBarButtonItem = leftItem;
    
    
    UIButton *deleteButton = [UIButton buttonWithType:0];
    deleteButton.size = CGSizeMake(40, 20);
    deleteButton.titleLabel.font = CustomUIFont(13);
    [deleteButton setTitle:@"删除" forState:0];
    [deleteButton addTarget:self action:@selector(deleteClick) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithCustomView:deleteButton];
    
    
    
    self.navigationItem.rightBarButtonItems = @[rightItem];

    if (![self.layout.dynamicModel.UserLocalId isEqualToString:USERID]){
        deleteButton.hidden = YES;
    }else{
        if (self.isMyDynamic){
            self.navigationItem.rightBarButtonItems = @[rightItem];
        }
    }
    
    WeakSelf
    
    CGFloat chatbarHeight = [HRMessageToolBar defaultHeight];
    self.chatToolbar = [[HRMessageToolBar alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - chatbarHeight, self.view.frame.size.width, chatbarHeight) keyboardType:DXKeyboardTypeNoPhoto];
    self.chatToolbar.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
    self.chatToolbar.inputTextView.placeHolder = [NSString stringWithFormat:@"发言"];

    //Initializa the gesture recognizer
//    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(keyBoardHidden:)];
//    tap.delegate = self;
//    [self.view addGestureRecognizer:tap];
    if (self.dynamicID){// 需要获取动态详情接口
        [self getDynamicInfoContent];
    }else{
        [self getCommentList];
    }
    [self setupEmotion];
//    [self.view addSubview:self.voiceBubble];

    
}

- (UIImage *)imageForEmptyDataSet:(UIScrollView *)scrollView{
    return [UIImage imageNamed:@"暂无评论"];
}
- (CGFloat)verticalOffsetForEmptyDataSet:(UIScrollView *)scrollView
{
    if ((self.layout.cellHeight - self.tableView.height/2) && (( self.tableView.height -self.layout.cellHeight) > 124)){
        return  self.layout.cellHeight - self.tableView.height/2+124+20;
    }
    return 0;
}

- (BOOL)emptyDataSetShouldAllowTouch:(UIScrollView *)scrollView
{
    return NO;
}

- (BOOL)emptyDataSetShouldAllowScroll:(UIScrollView *)scrollView
{
    return YES;
}


- (void)getCommentList{
    self.pIndex = 0;

    [self getCommentList:YES];
    WeakSelf
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        weakSelf.pIndex = 0;
        [self getCommentList:YES];
        [weakSelf.tableView.mj_header endRefreshing];

        
    }];
    
    //    //上拉加载
    self.tableView.mj_footer=[MJRefreshAutoStateFooter footerWithRefreshingBlock:^{
        weakSelf.pIndex ++;
        [weakSelf getCommentList:NO];
        [weakSelf.tableView.mj_footer endRefreshing];

        
    }];
}


- (void)getCommentList:(BOOL)isHead{
    
    WeakSelf
    
    HRDynamicGetCommentRequestModel *requestModel = [HRDynamicGetCommentRequestModel new];
    requestModel.momentLocalId = weakSelf.layout.dynamicModel.LocalId;
    requestModel.pageSize = 10;
    requestModel.pageIndex = self.pIndex;
    requestModel.currentUserLocalId = USERID;
    [self.viewModel getCommentListParam:requestModel isSeccess:^(NSArray *commentArr) {
        
        [MBProgressHUD hideHUDForView:WINDOW animated:YES];
        
        if (isHead){
            [weakSelf.tableViewModel.contentArray removeAllObjects];
        }
        [weakSelf.tableViewModel.contentArray addObjectsFromArray:commentArr];
        
        
        
        dispatch_async(dispatch_get_main_queue(), ^{
            [weakSelf.tableView reloadData];
            
            if (commentArr.count < requestModel.pageSize){
                weakSelf.tableView.mj_footer.hidden = YES;
            }else{
                
                weakSelf.tableView.mj_footer.hidden = NO;
            }
            
            if (isHead){
                NSMutableArray *arr = [NSMutableArray array];
                for (int i =0; i < weakSelf.tableViewModel.contentArray.count; i ++) {
                    if (i < 3){
                        HRDynamicCommentModel *commentModel = weakSelf.tableViewModel.contentArray[i];
                        [arr addObject:commentModel];
                    }
                }
                if (weakSelf.reloadListBlock){
                    weakSelf.reloadListBlock(arr);
                }
            }
        });
    }];
}




#pragma 点赞
- (void)getDynamicLike:(BOOL)isLike{
    
    WeakSelf
    
    if (isLike){
        [weakSelf.likesModel getLikeRequest:@{@"MomentLocalId":self.layout.dynamicModel.LocalId,@"LocalId":self.layout.dynamicModel.LocalId,@"UserLocalId":USERID,@"CreateTime":[self getCurrentTime]} isSeccess:^(BOOL isSeccess) {
            if(isSeccess){
                self.layout.dynamicModel.LikeCount = self.layout.dynamicModel.LikeCount+1;
                self.layout.dynamicModel.IsLike = @"1";
                if (weakSelf.reloadListBlock){
                    weakSelf.reloadListBlock(@[]);
                }
            }
        }];
        
    }else{
        [weakSelf.likesModel getDeletLikeRequest:@{@"MomentLocalId":self.layout.dynamicModel.LocalId,@"UserLocalId":USERID} isSeccess:^(BOOL isSeccess) {
            if (isSeccess){
                if (self.layout.dynamicModel.LikeCount){
                    self.layout.dynamicModel.LikeCount = self.layout.dynamicModel.LikeCount-1;
                }
                self.layout.dynamicModel.IsLike = @"0";
                if (weakSelf.reloadListBlock){
                    weakSelf.reloadListBlock(@[]);
                }
            }
        }];
    }
}

- (NSString *)getCurrentTime
{
    
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"YYYY-MM-dd hh:mm:ss"];
    
    return [formatter stringFromDate:[NSDate date]];
}

#pragma 删除帖子
- (void)deleteClick{
    
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提示" message:@"确定删除该动态？" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    alertView.alertViewStyle=UIAlertViewStyleDefault;
    
    [alertView show];
    
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex == 1){
        WeakSelf
        [self.viewModel deleteDynamic:@{@"LocalId":self.layout.dynamicModel.LocalId,@"UserLocalId":self.layout.dynamicModel.UserLocalId} isSeccess:^(BOOL isSeccess) {
            if (isSeccess){
                if (weakSelf.removeCircleBlock){
                    weakSelf.removeCircleBlock();
                }
                [MBProgressHUD showMessage:@"删除成功" finishBlock:nil];
                [weakSelf.navigationController popViewControllerAnimated:YES];
            }
        }];
    }
}


- (void)deleteCommentIndex:(NSUInteger)index{
    HRDynamicCommentModel *model = self.tableViewModel.contentArray[index];
    [[NSUserDefaults standardUserDefaults] setInteger:1 forKey:@"cacheTime"];

    WeakSelf
    if ([model.UserLocalId isEqualToString:USERID]){
        [self.viewModel deleteComment:@{@"LocalId":model.LocalId,@"UserLocalId":USERID} isSeccess:^(BOOL isSeccess) {
            if (isSeccess){
                [weakSelf.tableViewModel.contentArray removeObjectAtIndex:index];
                [weakSelf.headView.dynamicToolView.messageButton setTitle:[NSString stringWithFormat:@"  %ld",weakSelf.tableViewModel.contentArray.count] forState:0];
                [weakSelf.tableView reloadData];
                [MBProgressHUD showMessage:@"删除成功" finishBlock:nil];
            }
        }];
    }
}
#pragma 评论
- (void)answerComment:(NSString *)contentStr andType:(NSString *)type andUrlLength:(NSString *)urlLength{

    MJWeakSelf

    if ([type isEqualToString:@"2"]){
        [OSSImageUploader asyncUploadSound:@[contentStr] complete:^(NSArray<NSString *> *names, UploadImageState state) {
            if (state == UploadImageFailed) return ;
            dispatch_async(dispatch_get_main_queue(), ^{
                [weakSelf postAnswerComment:[NSString stringWithFormat:@"http://%@.%@%@",BucketName,AliYunHost,[names firstObject]] andType:type andUrlLength:urlLength];
            });
        }];
    }else{
        [weakSelf postAnswerComment:contentStr andType:type andUrlLength:urlLength];
    }
}

- (void)postAnswerComment:(NSString *)contentStr andType:(NSString *)type andUrlLength:(NSString *)urlLength{
    WeakSelf
    
    HRDynamicCommentRequestModel *requestModel = [HRDynamicCommentRequestModel new];
    requestModel.LocalId = USERID;
    requestModel.UserLocalId = USERID;
    requestModel.MomentLocalId = weakSelf.layout.dynamicModel.LocalId;
    requestModel.CommentText = contentStr;
    
    requestModel.IsRead = 0;
    requestModel.MainCommentLocalId = @"";

    if (self.tempCommentModel){
        requestModel.CommentLevel = @"2";
        requestModel.ReplyUserLocalId = self.tempCommentModel.UserLocalId;
        requestModel.MainCommentLocalId = self.tempCommentModel.LocalId;
        
    }else{
        requestModel.ReplyUserLocalId = @"";
        requestModel.CommentLevel = @"1";
    }
    requestModel.CreateTime = [weakSelf getCurrentTime];
    requestModel.CommentType = type;
    requestModel.SoundLength = urlLength;
    requestModel.SoundUrl = contentStr;
    if ([type isEqualToString:@"2"]){
        requestModel.CommentText = @"";
    }else{
        requestModel.SoundLength = @"0";
        requestModel.SoundUrl = @"";
    }
    
    
    [weakSelf.viewModel postDynamicCommentParam:requestModel AndCommentModel:^(HRDynamicCommentModel *commentModel) {
        
        weakSelf.tempCommentModel = nil;
        
        weakSelf.chatToolbar.inputTextView.placeHolder = [NSString stringWithFormat:@"发言"];
        
        weakSelf.layout.dynamicModel.CommentCount += 1;
        
        [weakSelf.headView.dynamicToolView.messageButton setTitle:[NSString stringWithFormat:@"  %ld",(long)weakSelf.layout.dynamicModel.CommentCount] forState:0];
        [weakSelf.chatToolbar endEditing:YES];
        
        [weakSelf getCommentList:YES];
        
        
        [MBProgressHUD showMessage:@"评论成功" finishBlock:nil];
    }];
}



-(void)keyBoardHidden:(UITapGestureRecognizer *)tapRecognizer
{
    if (tapRecognizer.state == UIGestureRecognizerStateEnded) {
        [self.chatToolbar endEditing:YES];
    }
}




- (void)clickBack{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)setChatToolbar:(HRMessageToolBar *)chatToolbar
{
    [_chatToolbar removeFromSuperview];
    
    _chatToolbar = chatToolbar;
    if (_chatToolbar) {
        [self.view addSubview:_chatToolbar];
    }
    
    CGRect tableFrame = self.tableView.frame;
    tableFrame.size.height = self.view.frame.size.height - _chatToolbar.frame.size.height;
    self.tableView.frame = tableFrame;
    if ([chatToolbar isKindOfClass:[HRMessageToolBar class]]) {
        [(HRMessageToolBar *)self.chatToolbar setDelegate:self];
        //        self.chatBarMoreView = (EaseChatBarMoreView*)[(HRMessageToolBar *)self.chatToolbar moreView];
        self.faceView = (EaseFaceView*)[(HRMessageToolBar *)self.chatToolbar faceView];
    }
}
- (void)setDataSource:(id<EaseMessageViewControllerDataSource>)dataSource
{
    //    _dataSource = dataSource;
    
    [self setupEmotion];
}

#pragma mark - EMChatToolbarDelegate

- (void)didChangeFrameToHeight:(CGFloat)toHeight
{
    [UIView animateWithDuration:0.3 animations:^{
        CGRect rect = self.tableView.frame;
        rect.origin.y = 0;
        rect.size.height = self.view.frame.size.height - toHeight;
        self.tableView.frame = rect;
    }];
    
    [self _scrollViewToBottom:NO];
}

- (void)inputTextViewWillBeginEditing:(EaseTextView *)inputTextView
{
    //    if (_menuController == nil) {
    //        _menuController = [UIMenuController sharedMenuController];
    //    }
    //    [_menuController setMenuItems:nil];
}

- (void)didSendText:(NSString *)text
{
    
    if (text && text.length > 0) {
        //        [self sendTextMessage:text];
        //        [self.atTargets removeAllObjects];
        [self answerComment:text andType:@"1" andUrlLength:@"0"];
        
    }
}
- (void)didSendText:(NSString *)text withExt:(NSDictionary*)ext{
    
}



/*!
 @method
 @brief 设置表情
 @discussion 加载默认表情，如果子类实现了dataSource的自定义表情回调，同时会加载自定义表情
 @result
 */
- (void)setupEmotion
{
    if ([self.dataSource respondsToSelector:@selector(emotionFormessageViewController:)]) {
        NSArray* emotionManagers = [self.dataSource emotionFormessageViewController:self];
        [self.faceView setEmotionManagers:emotionManagers];
    } else {
        NSMutableArray *emotions = [NSMutableArray array];
        for (NSString *name in [EaseEmoji allEmoji]) {
            EaseEmotion *emotion = [[EaseEmotion alloc] initWithName:@"" emotionId:name emotionThumbnail:name emotionOriginal:name emotionOriginalURL:@"" emotionType:EMEmotionDefault];
            [emotions addObject:emotion];
        }
        EaseEmotion *emotion = [emotions objectAtIndex:0];
        EaseEmotionManager *manager= [[EaseEmotionManager alloc] initWithType:EMEmotionDefault emotionRow:3 emotionCol:7 emotions:emotions tagImage:[UIImage imageNamed:emotion.emotionId]];
        [self.faceView setEmotionManagers:@[manager]];
    }
}

- (void)didStartRecordingVoiceAction:(UIView *)recordView
{
    if ([self _canRecord]) {

        int x = arc4random() % 100000;
        NSTimeInterval time = [[NSDate date] timeIntervalSince1970];
        NSString *fileName = [NSString stringWithFormat:@"%d%d",(int)time,x];
        
        [[EMCDDeviceManager sharedInstance] asyncStartRecordingWithFileName:fileName completion:^(NSError *error)
         {
             if (error) {
                 NSLog(@"%@",NSEaseLocalizedString(@"message.startRecordFail", @"failure to start recording"));
             }
         }];
    }
}

- (void)didCancelRecordingVoiceAction:(UIView *)recordView
{
    [[EMCDDeviceManager sharedInstance] cancelCurrentRecording];

}

#pragma 发送语音
- (void)didFinishRecoingVoiceAction:(UIView *)recordView andRecordPath:(NSString *)recordPath andDuration:(NSInteger)aDuration
{

    NSString *wavFilePath = [[recordPath stringByDeletingPathExtension]
                               stringByAppendingPathExtension:@"wav"];
    BOOL convertResult = [self convertAMR:recordPath toWAV:wavFilePath];
    if (convertResult){
        NSFileManager *fm = [NSFileManager defaultManager];
        [fm removeItemAtPath:recordPath error:nil];
        
    }else{
        
    }
    
    [self answerComment:wavFilePath andType:@"2" andUrlLength:[NSString stringWithFormat:@"%d",aDuration]];
}

- (BOOL)convertAMR:(NSString *)amrFilePath
             toWAV:(NSString *)wavFilePath
{
    BOOL ret = NO;
    BOOL isFileExists = [[NSFileManager defaultManager] fileExistsAtPath:amrFilePath];
    if (isFileExists) {
        [EMVoiceConverter amrToWav:amrFilePath wavSavePath:wavFilePath];
        isFileExists = [[NSFileManager defaultManager] fileExistsAtPath:wavFilePath];
        if (isFileExists) {
            ret = YES;
        }
    }
    
    return ret;
}

- (void)didDragInsideAction:(UIView *)recordView
{
    if ([self.recordView isKindOfClass:[HRMeeageRecordView class]]) {
        [(HRMeeageRecordView *)self.recordView recordButtonDragInside];
    }
}

- (void)didDragOutsideAction:(UIView *)recordView
{
    if ([self.recordView isKindOfClass:[HRMeeageRecordView class]]) {
        [(HRMeeageRecordView *)self.recordView recordButtonDragOutside];
    }
}

/*!
 @method
 @brief tableView滑动到底部
 @discussion
 @result
 */
- (void)_scrollViewToBottom:(BOOL)animated
{
    if (self.tableView.contentSize.height > self.tableView.frame.size.height)
    {
        CGPoint offset = CGPointMake(0, self.tableView.contentSize.height - self.tableView.frame.size.height);
        [self.tableView setContentOffset:offset animated:animated];
    }
}
/*!
 @method
 @brief 当前设备是否可以录音
 @discussion
 @result
 */
- (BOOL)_canRecord
{
    __block BOOL bCanRecord = YES;
    if ([[[UIDevice currentDevice] systemVersion] compare:@"7.0"] != NSOrderedAscending)
    {
        AVAudioSession *audioSession = [AVAudioSession sharedInstance];
        if ([audioSession respondsToSelector:@selector(requestRecordPermission:)]) {
            [audioSession performSelector:@selector(requestRecordPermission:) withObject:^(BOOL granted) {
                bCanRecord = granted;
            }];
        }
    }
    
    return bCanRecord;
}




#pragma 获取动态详情
- (void)getDynamicInfoContent{
    WeakSelf
    [self.viewModel getDynamicInfoContent:@{@"LocalId":self.dynamicID,@"UserLocalId":USERID} isSeccess:^(HRFollowDynamicLayout *layout) {
        if (layout){
            
            weakSelf.headView.layout = layout;
            weakSelf.layout = layout;
            weakSelf.headView.height = layout.cellHeight;
            [self getCommentList];
        }
    }];
}

#pragma 二级评论
- (void)towAnswerForSomenone:(HRDynamicCommentModel *)commentModel{
    
    if ([commentModel.UserLocalId isEqualToString:USERID]){
//        [self.chatToolbar.text setTitle:kTouchToRecord forState:UIControlStateNormal];
        self.chatToolbar.inputTextView.placeHolder = [NSString stringWithFormat:@"发言"];
        self.tempCommentModel = nil;
    }else{
//        [self.chatToolbar.recordButton setTitle:[NSString stringWithFormat:@"回复：%@ %@",commentModel.CommentUserNickName,kTouchToRecord] forState:UIControlStateNormal];
        self.chatToolbar.inputTextView.placeHolder = [NSString stringWithFormat:@"回复：%@",commentModel.CommentUserNickName];
        self.tempCommentModel = commentModel;
    }
}


-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    
//    if ([_layout.dynamicModel.MomentType intValue] !=4)return;
//    [self.headView.videoImageView jp_playVideoWithURL:[NSURL URLWithString:_layout.dynamicModel.MomentDetai]];
    
//    [self.headView.videoImageView jp_perfersPlayingProgressViewColor:[UIColor redColor]];
//    [self.headView.videoImageView jp_perfersDownloadProgressViewColor:[UIColor lightGrayColor]];
    
    
//    self.muteSwitch.on = ![self.videoImv jp_playerIsMute];
//    self.playOrPauseSwitch.on = self.videoImv.playingStatus == JPVideoPlayerPlayingStatusPlaying ? NO : YES;
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.chatToolbar endEditing:YES];
    [[NSNotificationCenter defaultCenter] postNotificationName:@"stopPlayVoiceNotification" object:nil];
//    [self.headView.videoImageView jp_stopPlay];
}



-(void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
    [[NSUserDefaults standardUserDefaults] setInteger:300 forKey:@"cacheTime"];

}
//
//
//- (void)voiceBubbleDidStartPlaying:(ZFJVoiceBubble *)voiceBubble{
//    
//}
//
//- (void)voiceBubbleStratOrStop:(BOOL)isStart{
//    if (isStart){
//        
//    }else{
//        [self.voiceBubble stopAnimating];
//    }
//}// YES 开始播放  NO 停止播放



- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.hidesBottomBarWhenPushed = YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
